package com.lijinjiang.reflect03_field;

import org.junit.Test;

import java.lang.reflect.Field;

/**
 * @ClassName TestField01
 * @Description TODO
 * @Author Li
 * @Date 2022/9/20 20:57
 * @ModifyDate 2022/9/20 20:57
 * @Version 1.0
 */
public class TestField01 {
    // 1.getFields()
    // 2.getDeclaredFields()
    @Test
    public void testGetDeclaredFields() {
        // 1.获取 class 对象
        Class c = Student.class;
        // 2.获取公共成员变量数组
        Field[] fields = c.getDeclaredFields();
        // 3.遍历
        for (Field field : fields) {
            System.out.println(field.getName() + "===>" + field.getType());
        }
    }
    // 3.getField(String name)
    // 4.getDeclaredField(String name)
    @Test
    public void testGetDeclaredField() throws Exception {
        // 1.获取 class 对象
        Class c = Student.class;
        // 2.获取公共成员变量数组
        Field field = c.getDeclaredField("age");
        // 3.输出
        System.out.println(field.getName() + "===>" + field.getType());
    }
}
